<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../back-common.jsp"%>
<%@ include file="/WEB-INF/pages/common/taglib.jsp"%>
<%@ include file="/WEB-INF/pages/common/back-dialog.jsp"%>
<%@ taglib uri="http://displaytag.sf.net" prefix="display"%>
  <link rel="stylesheet" href="${contextPath}/resources/templets/amaze/css/amazeui.css"/>
  <link rel="stylesheet" href="${contextPath}/resources/templets/amaze/css/admin.css">
  <!--[if lt IE 9]>
<script src="${contextPath}/resources/templets/amaze/js/modernizr.js"></script>
<script src="${contextPath}/resources/templets/amaze/js/amazeui.ie8polyfill.min.js"></script>
<![endif]-->
<!--[if (gte IE 9)|!(IE)]><!-->
<!--<![endif]-->
<script src="${contextPath}/resources/templets/amaze/js/amazeui.min.js"></script>
<script src="${contextPath}/resources/templets/amaze/js/app.js"></script>
<script type='text/javascript' src="<ls:templateResource item='/resources/common/js/jquery.validate.js'/>" ></script>
        <div align="center">
          <%@ include file="/WEB-INF/pages/common/messages.jsp"%>
		<display:table name="list" requestURI="/admin/task/queryContent/${taskQueryDto.projectId}" id="item" export="false" sort="external" class="${tableclass}" style="width:100%">
		    <display:column title="ID" property="id" sortable="true" sortName="t1.id"></display:column>
		    <display:column title="P" property="priority"  sortable="true" sortName="t1.priority" style="width:10px"></display:column>
		    <c:if test="${queryAllTask}">
		        <display:column title="项目" sortable="true" sortName="t1.projectName" style="min-width: 200px">
     				${item.projectName}
     			</display:column>
		    </c:if>
     		<display:column title="目标名称"  sortable="true" sortName="t1.name" style="min-width: 250px">
     			<font color="${item.color}">${item.name}</font>
     		</display:column>
     		<display:column title="状态" sortable="true" sortName="t1.status" style="min-width: 60px">
     		    <c:choose>
     				<c:when test="${item.status eq 1}"><font color="green">
						<ls:optionGroup type="label" required="true" cache="true"  beanName="TASK_STATUS" selectedValue="${item.status}"/>
					</font></c:when>
     				<c:otherwise>
						<ls:optionGroup type="label" required="true" cache="true" beanName="TASK_STATUS" selectedValue="${item.status}"/>
					</c:otherwise>
     			</c:choose>
     		</display:column>
     		<display:column title="创建" sortable="true" sortName="t1.createTime"  style="min-width: 90px"><fmt:formatDate value="${item.createTime}" pattern="yyyy-MM-dd"/></display:column>
     		<display:column title="截止"  sortable="true" sortName="t1.deadline"  style="min-width: 90px"><fmt:formatDate value="${item.deadline}" pattern="yyyy-MM-dd"/></display:column>
     		<display:column title="指派给"  sortable="true" sortName="t1.assignedtoRealName"  property="assignedtoRealName" style="min-width: 80px"></display:column>
     		<display:column title="完成者" sortable="true" sortName="t1.finishedby" property="finishedby" style="min-width: 80px"></display:column>
     		<display:column title="消耗" sortable="true" sortName="t1.totalConsumed" property="totalConsumed" style="min-width: 60px"></display:column>
     		<display:column title="剩" sortName="t1.leftHours"  property="leftHours" style="min-width: 60px" media="html" ></display:column>
     		<%-- 
     		<display:column title="进度" property="rate" style="min-width: 60px"></display:column>
     		--%>
	   		<display:column title="操作" media="html" style="min-width: 250px">
		      	<div class="am-btn-toolbar">
			      <div class="am-btn-group am-btn-group-xs">
				     <button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="window.location.href='${contextPath}/admin/task/load/${item.id}'">
				     <span class="am-icon-search"></span>查看</button>
				     <button class="am-btn am-btn-default am-btn-xs am-text-secondary" onclick="javascript:taskEstimate(this, '${item.id}')"><span class="am-icon-search"></span>工时</button>
					 <div class="am-dropdown" data-am-dropdown>
		                <button class="am-btn am-btn-default am-btn-xs am-dropdown-toggle" data-am-dropdown-toggle><span class="am-icon-cog"></span> <span class="am-icon-caret-down"></span></button>
		                <ul class="am-dropdown-content">
		                  <li><a href="javascript:assignTask(this, '${item.id}')">指派</a></li>
		                  <li><a href="javascript:startTask(this, '${item.id}')">开始</a></li>
		                  <li><a href="javascript:finishTask(this, '${item.id}')">完成</a></li>
		                  <li><a href="javascript:cancelTask(this, '${item.id}')">取消</a></li>
		                  <li><a href="javascript:closeTask(this, '${item.id}')">关闭</a></li>
		                 </ul>
	              </div>
              		<button class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only" onclick="javascript:deleteById('${item.id}')"><span class="am-icon-trash-o"></span> 删除</button>
				 </div>
			 	</div>
	       </display:column>
	    </display:table>
	    <ls:page pageSize="${pageSize }"  total="${total}" curPageNO="${curPageNO }"  type="default"/> 
	    </div>
		 <div style="margin: 15px;" align="left">
		 <c:if test="${totalConsumed > 0}">
			  消耗的总工时&nbsp; <b>${totalConsumed }</b>&nbsp;小时，
			  消耗的总人天是&nbsp; <b><fmt:formatNumber value="${totalConsumed/8 }" pattern="#.##" maxFractionDigits="2" /></b>&nbsp;，
			  消耗的总人月是&nbsp;<b><fmt:formatNumber value="${totalConsumed/8/24 }" pattern="#.##" maxFractionDigits="2" /></b>&nbsp;<br/>
		  </c:if>
		  <c:if test="${leftHours > 0}">
			  预计总剩余时间&nbsp;<b> ${leftHours }</b>&nbsp;小时
			  预计总剩余人天是&nbsp; <b><fmt:formatNumber value="${leftHours/8 }" pattern="#.##" maxFractionDigits="2" /></b>&nbsp;，
			  预计总剩余人月是&nbsp;<b><fmt:formatNumber value="${leftHours/8/24 }" pattern="#.##" maxFractionDigits="2" /></b>&nbsp;
		  </c:if>
		 </div>
        <script language="JavaScript" type="text/javascript">
			  function deleteById(id) {
			      layer.confirm("确定删除吗1？", {
			 		 icon: 3
			 	     ,btn: ['确定','关闭'] //按钮
			 	   }, function(){
			 		   console.log("");
			        	$.ajax({
			          		url : "${contextPath}/admin/task/delete/" +id,
			          		type : "PUT",
			          		dataType :"JSON",
			          		async : true,
			          		error : function(xhr,status,error){
			          			layer.msg("网络错误,请稍后重试!");
			          		},
			          		success : function(result,status,xhr){
			          			if(result == "success"){
			          				layer.closeAll('dialog'); //关闭信息框
			          				sendData();
			          			}else{
			          				 layer.msg("删除目标失败，该目标已经有对应的审核过的日志");
			          			}
			          		}
			          	});
				 });
			    }
			  
			   	 //为成员设置项目
			    function assignTask(obj, taskId){
			    		var page = contextPath + "/admin/task/assignTask/" + taskId;
			    		//iframe窗
			    		layer.open({
			    		  type: 2,
			    		  id: "assignTask",
			    		  title: "指派成员",
			    		  area: ['800px'],
			    		  content: page, //iframe的url，no代表不显示滚动条
			    		  success: function(layero, index) {
			    		        layer.iframeAuto(index);
			    		        layer.style(index, {
			    		        	  top: '60px'
			    		        	}); 
			    		    }
			    		});
			    	}
			   	 
			   	 //开始项目
			    function startTask(obj, taskId, status){
			    		var page = contextPath + "/admin/task/startTask/" + taskId;
			    		layer.open({
				    		  type: 2,
				    		  id: "startTask",
				    		  title: "开始目标",
				    		  area: ['900px'],
				    		  content: page, //iframe的url，no代表不显示滚动条
				    		  success: function(layero, index) {
				    		        layer.iframeAuto(index);
				    		        layer.style(index, {
				    		        	  top: '60px'
				    		        	}); 
				    		    }
				    		});
			    	}
			   	 
			   	 
			   	 //完成项目
			    function finishTask(obj, taskId, status){
			    		var page = contextPath + "/admin/task/finishTask/" + taskId;
			    		layer.open({
				    		  type: 2,
				    		  id: "finishTask",
				    		  title: "完成目标",
				    		  area: ['800px'],
				    		  content: page, //iframe的url，no代表不显示滚动条
				    		  success: function(layero, index) {
				    		        layer.iframeAuto(index);
				    		        layer.style(index, {
				    		        	  top: '60px'
				    		        	}); 
				    		    }
				    		});
			    	}
			   	 
			   	 //关闭项目
			    function closeTask(obj, taskId, status){
			    		var page = contextPath + "/admin/task/closeTask/" + taskId;
			    		layer.open({
				    		  type: 2,
				    		  id: "closeTask",
				    		  title: "关闭目标",
				    		  area: ['800px'],
				    		  content: page, //iframe的url，no代表不显示滚动条
				    		  success: function(layero, index) {
				    		        layer.iframeAuto(index);
				    		        layer.style(index, {
				    		        	  top: '60px'
				    		        	}); 
				    		    }
				    		});
			    	}
			   	 
			   	 //取消项目
			    function cancelTask(obj, taskId, status){
			    		var page = contextPath + "/admin/task/cancelTask/" + taskId;
			    		layer.open({
				    		  type: 2,
				    		  id: "cancelTask",
				    		  title: "取消目标",
				    		  area: ['900px'],
				    		  content: page, //iframe的url，no代表不显示滚动条
				    		  success: function(layero, index) {
				    		        layer.iframeAuto(index);
				    		        layer.style(index, {
				    		        	  top: '60px'
				    		        	}); 
				    		    }
				    		});
			    	}
			   	 
			   	 //工时
			    function taskEstimate(obj, taskId, status){
			    		var page = contextPath + "/admin/task/taskEstimate/" + taskId;
			    		layer.open({
				    		  type: 2,
				    		  id: "taskEstimate",
				    		  title: " 目标ID:" + taskId,
				    		  area: ['900px'],
				    		  content: [page,'no'], //iframe的url，no代表不显示滚动条
				    		  success: function(layero, index) {
				    		        layer.iframeAuto(index);
				    		        layer.style(index, {
				    		        	  top: '60px'
				    		        	}); 
				    		    }
				    		});
			    	}	   	 
			    
			   	 
			   	//打开弹层时关闭下拉列表
			    function closeDropdown(){
		    		$(".am-dropdown").dropdown('close');
		    		
		    	}   	 
			        
		</script>

